public class Solution extends GuessGame {
    public int guessNumber(int n) {
        int low = 1;
        int high = n;
        while(true) {
            int mid = low+(high-low) / 2;
            switch(guess(mid)) {
                case 1:
                    low = mid + 1;
                    break;
                case -1:
                    high = mid - 1;
                    break;
                case 0:
                    return mid;
            }
        }
    }
}